{extend name="common@base/common" /}
{block name="style"}
<link rel="stylesheet" href="__JS__/codemirror/codemirror.css">
<style>
    .CodeMirror, #preview_window {
        width: 700px;
        height: 500px;
    }

    #preview_window.loading {
        background: url('__STATIC__/thinkbox/skin/default/tips_loading.gif') no-repeat center;
    }

    #preview_window textarea {
        display: none;
    }
</style>
{/block}
{block name="body"}
<!-- 表单 -->
<form id="form" action="{:U('build')}" method="post" class="form-horizontal doc-modal-form">
    <div class="form-item">
        <label class="item-label"><span class="must">*</span>标识名 <span class="check-tips">（应用的英文字，只能英文字母，不能有数字，下划线等，多个单词组合时用下划线隔开，如 user_center）</span></label>
        <div class="controls">
            <input type="text" class="text input-large" name="info[name]" value="example">
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">应用名<span class="check-tips">（应用中文名）</span></label>
        <div class="controls">
            <input type="text" class="text input-large" name="info[title]" value="示列">
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">版本<span class="check-tips">（请输入应用版本）</span></label>
        <div class="controls">
            <input type="text" class="text input-large" name="info[version]" value="0.1">
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">作者<span class="check-tips">（请输入应用作者）</span></label>
        <div class="controls">
            <input type="text" class="text input-large" name="info[author]" value="凡星">
        </div>
    </div>
    <div class="form-item">
        <label class="item-label">描述<span class="check-tips">（请输入描述）</span></label>
        <div class="controls">
            <label class="textarea input-large">
                <textarea name="info[description]">这是一个临时描述</textarea>
            </label>
        </div>
    </div>
    <input type="hidden" name="has_outurl" value="1"/>
    <div class="form-item">
        <label class="item-label">是否需要管理列表</label>
        <div class="controls">
            <label class="checkbox">
                <input type="checkbox" id="has_adminlist" name="has_adminlist" value="1" checked/>如应用数据有管理列表，则选择是，如：<a
                    href="{:U ( 'weixin/user_center/lists' )}" target="_blank">微信用户应用的管理列表</a>
            </label>
        </div>
    </div>

    <div class="form-item">
        <button class="btn ajax-post_custom submit-btn" target-form="form-horizontal" id="submit">创建并安装</button>
        <button class="btn btn-return">返 回</button>
    </div>
</form>
{/block}

{block name="script"}
<script type="text/javascript" src="__JS__/codemirror/codemirror.js?v={:SITE_VERSION}"></script>
<script type="text/javascript" src="__JS__/codemirror/xml.js?v={:SITE_VERSION}"></script>
<script type="text/javascript" src="__JS__/codemirror/javascript.js?v={:SITE_VERSION}"></script>
<script type="text/javascript" src="__JS__/codemirror/clike.js?v={:SITE_VERSION}"></script>
<script type="text/javascript" src="__JS__/codemirror/php.js?v={:SITE_VERSION}"></script>

<script type="text/javascript" src="__STATIC__/thinkbox/jquery.thinkbox.js?v={:SITE_VERSION}"></script>

<script type="text/javascript">
    function bindShow(radio_bind, selectors) {
        $(radio_bind).click(function () {
            $(selectors).toggleClass('hidden');
        })
    }

    //配置的动态
    bindShow('#has_config', '.has_config');
    bindShow('#has_adminlist', '.has_adminlist');

    $('.ajax-post_custom').click(function () {
        var target, query, form;
        var target_form = $(this).attr('target-form');
        var check_url = '{:U(\'checkForm\')}';
        $.ajax({
            type: "POST",
            url: check_url,
            dataType: 'json',
            async: false,
            data: $('#form').serialize(),
            success: function (data) {
                if (data.code==0) {
                    if (($(this).attr('type') == 'submit') || (target = $(this).attr('href')) || (target = $(this).attr('url'))) {
                        form = $('.' + target_form);
                        if (form.get(0).nodeName == 'FORM') {
                            target = form.get(0).action;
                            query = form.serialize();
                        } else if (form.get(0).nodeName == 'INPUT' || form.get(0).nodeName == 'SELECT' || form.get(0).nodeName == 'TEXTAREA') {
                            query = form.serialize();
                        } else {
                            query = form.find('input,select,textarea').serialize();
                        }
                        $.post(target, query).success(function (data) {
                            if (data.code == 0) {
                                if (data.url) {
                                    updateAlert(data.msg + ' 页面即将自动跳转~', 'alert-success');
                                } else {
                                    updateAlert(data.msg + ' 页面即将自动刷新~');
                                }
                                setTimeout(function () {
                                    if (data.url) {
                                        location.href = data.url;
                                    } else {
                                        location.reload();
                                    }
                                }, 1500);
                            } else {
                                updateAlert(data.msg);
                            }
                        });
                    }
                } else {
                    updateAlert(data.msg);
                }
            }
        });

        return false;
    });
</script>
{/block}
